import { defineStore } from 'pinia'
import { getDict, getPermissions, getUserinfo, getPayInfo} from 'services/system'

interface PayPackage {
    id: number | undefined,
    can_select: boolean,
    date_type: number,
    date_type_desc: string,
    fee: number | undefined,
    discount: string,
    fee_per_month: string,
    offset_fee: number | undefined,
    total_fee: number | undefined,
    new_time: string
}

interface Dict {
    id: number,
    name: string,
    append_value:string
}

interface PayInfo {
    id: number | undefined,
    name: string,
    account_num: number | undefined,
    order_num: number | undefined,
    data_keep_day: number | undefined | null,
    bi_permission: number | undefined | null,
    data_analyze: number | undefined | null,
    package_list:PayPackage[],
    pay_type:Dict[]
}

let payInfo:PayInfo= {
    id:0,
    name:'',
    account_num:0,
    order_num:0,
    data_keep_day:0,
    bi_permission:0,
    data_analyze:0,
    pay_type:[],
    package_list:[],
}

const systemStore = defineStore('system', {
    state: () => ({
        dict: <any>{},
        userInfo: {
            agent_type:'',
            id:'',
            mobile:'',
            real_name:''
        },
        levelInfo: {
            name:'',
            account_num:0,
            order_num:0,
            data_keep_day:0,
            bi_permission:0,
            data_analyze:0,
            account_usage_num:0,
            order_usage_num:0,
            compare_list:<any>[]
        },
        permissions: {},
        levelDialog: false,
        recharge:false,
        payInfo:payInfo,
        payStateDialog:false,
        payFailDialog:false,
        paySuccessDialog:false,
        pastdueDialog:false,
        pastdueDate:0,
        purchase_id:0
    }),
    actions: {
        async getUserInfo() {
            let res = await getUserinfo()
            console.log(res)
            this.userInfo = res
        },
        async getDict() {
            this.dict = await getDict()
        },
        async getPermissions() {
            this.permissions = await getPermissions()
        },
        
        setLevelDialog(val:boolean){
            this.levelDialog = val
        },
        setRecharge(val:boolean){
            this.recharge = val
        },
        async getPayInfo(level_id:number) {
            let res = await getPayInfo({level_id})
            this.payInfo = res
            this.recharge = true
        },
        setPayStateDialog(val:boolean){
            this.payStateDialog = val
        },
        setPayFailDialog(val:boolean){
            this.payFailDialog = val
        },
        setPaySuccessDialog(val:boolean){
            this.paySuccessDialog = val
        },
        setPastdueDialog(val:boolean){
            this.pastdueDialog = val
        },
        setPurchaseId(val:number){
            this.purchase_id = val
        }
    }
})

export default systemStore